package com.blumov.fastbox.infrastructure.persistence.dataaccess.simpledao;

import java.io.Serializable;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.classic.Session;

/**
 * Operaciones basicas de persistencia <br>
 * 
 * @see Session
 * @see Query
 */
public interface SimpleDAO {

	/**
	 * @see Session#save(Object)
	 */
	Integer save(Object obj);

	/**
	 * @see Session#update(Object)
	 */
	void update(Object obj);

	/**
	 * @see Session#saveOrUpdate(Object)
	 */
	void saveOrUpdate(Object obj);
	
	/**
	 * @return
	 * @see Session#merge(Object)
	 */
	Object merge(Object obj);

	/**
	 * @see Session#delete(String, Object)
	 */
	@SuppressWarnings("unchecked")
	void delete(Class theClass, Integer id);
	
	/**
	 * @see Session#delete(Object)
	 */
	void delete(Object obj);

	/**
	 * @see Session#load(Class, java.io.Serializable)
	 */
	@SuppressWarnings("unchecked")
	Object load(Class theClass, Serializable id);

	/**
	 * @see Session#get(Class, Serializable)
	 */
	@SuppressWarnings("unchecked")
	Object get(Class theClass, Serializable id);
	
	/**
	 * @see Session#createQuery(String)
	 */
	Query createQuery(String queryString);

	/**
	 * 
	 * @see Session#createSQLQuery(String)
	 */
	Query createSQLQuery(String queryString);
	
	/**
	 * @see Session#createCriteria(Class)
	 */
	@SuppressWarnings("unchecked")
	Criteria createCriteria(Class persistentClass);
	
	/**
	 * @see Session#createCriteria(Class, String)
	 */
	@SuppressWarnings("unchecked")
	Criteria createCriteria(Class persistentClass, String alias);
	
	/**
	 * @see Session#getNamedQuery(String)
	 */
	Query getNameQuery(String queryName);
	
	
	/**
	 * @param <T>
	 * @param clazz
	 * @param id
	 * @param factory
	 * @return
	 */
	@SuppressWarnings("unchecked")
	<T> T loadOrCreate(Class clazz, Integer id, Factory<T> factory);

}
